import React, { Component } from 'react'
import request from '../util/request'

export default class Registry extends Component {
    state = {
        username:'',
        password:''
    }
    render() {
        let {username,password} = this.state;
        return (
            <div>
                <input placeholder="用户名" name="username" value={username} onChange={this.change}/>
                <input placeholder="密码" name="password" value={password} onChange={this.change}/>
                <button onClick={this.registry}>注册</button>
            </div>
        )
    }

    change = (e) => {
        this.setState({
            [e.target.name]:e.target.value
        })
    }
    //注册
    registry = () => {
        let {username,password} = this.state;
        if(username && password){
            request.post('/api/registry',{username,password}).then(res => {
                if(res.code === 1){
                    alert("注册成功");
                    // this.props.history.push('/login');
                }else{
                    alert("注册失败")
                }
            })
        }else{
            console.log("参数有误")
        }
    }
}